package com.yuliang.ai.controller;

import com.alibaba.fastjson.JSONObject;
import com.yuliang.ai.domain.Vo.*;
import com.yuliang.ai.service.AiUiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @author Huangkai
 */
@Slf4j
@RestController
@RequestMapping("/verity")
public class AiController {


    @Value("${spring.token1}")
    private String token1;

    @Value("${spring.token2}")
    private String token2;


    @Autowired
    AiUiService aiUiService;

    @RequestMapping(value = "/aiVerity", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String aiVerity(HttpServletRequest request) {
        return aiUiService.aiuiOperation(request, token1);
    }

    @PostMapping("/getVideoStream")
    public String getVideoStream(@RequestBody JSONObject jsonObject) {
        String text = jsonObject.getString("title");
        return aiUiService.getVideoStream(jsonObject, text);
    }

    @RequestMapping(value = "/aiOperation", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String aiOperation(@RequestBody HttpServletRequest request) {
        return aiUiService.aiuiOperation(request, token2);
    }

    @PostMapping("/getChatList")
    public String getChatList(@RequestBody ChatAnsVo chatAnsVo){
        return aiUiService.chatAnslist(chatAnsVo);
    }

    @PostMapping("/chatAnslist")
    public String chatAnslist(@RequestBody ChatAnsVo chatAnsVo){
        return aiUiService.chatAnslist(chatAnsVo);
    }

    @PostMapping("/stopChatAns")
    public String stopChatAns(@RequestBody @Validated ChatVo chatVo){
        return aiUiService.stopChatAns(chatVo);
    }
}
